package com.zzf.staservice.schedule;

import com.zzf.staservice.service.StatisticsDailyService;
import com.zzf.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTask {

    @Autowired
    private StatisticsDailyService dailyService;

    //测试方法
    //每隔五秒中执行一次
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void task1(){
//        System.out.println("task1 执行了");
//    }


    //每天凌晨一点定时执行,查询昨天统计数据,添加到统计表
    @Scheduled(cron = "0 0 1 * * ?")
    public void task2() {
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        dailyService.registerCount(day);
    }

}
